package learning.spring.family.mybatisdemo.mapper;

import learning.spring.family.mybatisdemo.model.Coffee;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Desc
 * @Author: yaw
 * @Date: Created in 21:56 2021/9/6
 * @Version: 1.0
 */
@Mapper
public interface CoffeeMapper {
    @Insert("insert into t_coffee(name,price,create_time,update_time) values(#{name},#{price},now(),now())")
    @Options(useGeneratedKeys = true)
    int save(Coffee coffee);

    @Select("select * from t_coffee where id =#{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    Coffee findById(@Param("id") Long id);

    @Select("select * from t_coffee")
    @Results({
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    List<Coffee> findAll();
}
